package com.bingbaihanji.hibernate.util;

import lombok.Getter;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author 冰白寒祭
 * @date 2024-03-22 22:47:48
 * @description //TODO
 */
public class HibernateUtil {

    private static final Configuration configuration;
    @Getter
    private static final SessionFactory sessionFactory;

    static {
        // 加载主配置文件封装成对象(默认配置文件在src目录下)
        configuration = new Configuration();
        configuration.configure();
        sessionFactory = configuration.buildSessionFactory();
    }
    // 提供与本地线程绑定的Session
    public static Session getSessionObject(){
        return sessionFactory.getCurrentSession();
    }

}
